<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
  <script src="./vue-router.js"></script>
</head>

<body>

  <div id="app">
    <ul>
      <router-link tag="li" to="/home">首页</router-link>
      <router-link tag="li" to="/position/beijing/1">前端开发</router-link>
      <router-link tag="li" to="/position/taiyuan/2">后端开发</router-link>
      <router-link tag="li" to="/search1">搜索</router-link>
      <router-link tag="li" to="/profile1">我的</router-link>
    </ul>
    <router-view></router-view>
  </div>


  <script>

    var position = {
      template: `<div>position:{{$route.params.cityname}}-{{$route.params.id}}</div>`,
      watch: {
        $route(to, from) {
          // 对路由变化作出响应...
          console.log(to,from)
        }
      }
    }
    var search = { template: `<div>search</div>` }
    var profile = { template: `<div>profile</div>` }

    var routes = [
      {
        path: "/",
        redirect: '/position'
      },
      {
        path:'*',
        component:{
          template:`<h1> 404 page no found</h1>`
        },
      },
      {
        path: '/position/:cityname/:id',
        component: position
      },
      {
        path: '/search',
        component: search
      },
      {
        path: '/profile',
        component: profile
      },
    ]

    var router = new VueRouter({
      routes
    })

    var vm = new Vue({
      router
    }).$mount('#app')

  </script>

</body>

</html>